﻿#include "Cache/OfflineCharacterData.h"


OfflineCharacterData::OfflineCharacterData() :m_charID(0)
											, m_nLevel(0)
											, m_bySex(0)
											, m_byProf(0)
											, m_nRace(0)
											, m_nFight(0)
											, m_byCampID(0)
											, m_byKnight(0)
											, m_nPrestige(0)
											, m_nHisPrestige(0)
											, m_byOfficial(0)
											, m_byContribute(0)
											, m_byContriCoin(0)
											, m_nKillCount(0)
											, m_intGold(0)
											, m_intDiamond(0)
											, m_useUnionContri(0)
											, m_historyContri(0)
											, m_lostCityVal(0)
											, m_exp(0)
											, m_hp(0)
											, m_maxHp(0)
											, m_charm(0)
{
	memset(m_szCharName, 0, sizeof(m_szCharName));
	memset(m_arrAchievementPoint, 0, sizeof(m_arrAchievementPoint));
	m_lastLogout = 0;
}

OfflineCharacterData::~OfflineCharacterData()
{
	Clear();
}

void OfflineCharacterData::Clear()
{
	memset(m_szCharName, 0, sizeof(m_szCharName));
	memset(m_arrAchievementPoint, 0, sizeof(m_arrAchievementPoint));
	m_uid = 0;
	m_charID = 0;
	m_nLevel = 0;
	m_bySex = 0;
	m_byProf = 0;
	m_nFight = 0;
	m_nRace = 0;
	m_byCampID = 0;
	m_byKnight = 0;
	m_nPrestige = 0;
	m_nHisPrestige = 0;
	m_byOfficial = 0;
	m_byContribute = 0;
	m_byContriCoin = 0;
	m_nKillCount = 0;
	m_intGold = 0;
	m_intDiamond = 0;
	m_useUnionContri = 0;
	m_lostCityVal = 0;
	m_charm = 0;
	m_lastLogout = 0;
}

//获取角色ID
CharIDType OfflineCharacterData::GetCharID()
{
	return m_charID;
}

//设置角色ID
void OfflineCharacterData::SetCharID(CharIDType charID)
{
	m_charID = charID;
}
//获取帐号uid
void OfflineCharacterData::SetUid(uint32_t uid)
{
	m_uid = uid;
}

uint32_t OfflineCharacterData::GetUid()
{
	return m_uid;
}

//获取角色名
const char *OfflineCharacterData::GetCharName()
{
	return m_szCharName;
}
//设置角色名字
void OfflineCharacterData::SetCharName(const char *szName)
{
	SafeCopyString(m_szCharName, sizeof(m_szCharName) - 1, szName);
}
//获取角色等级
int16_t OfflineCharacterData::GetLevel()
{
	return m_nLevel;
}
//设置等级
void OfflineCharacterData::SetLevel(int16_t nLevel)
{
	m_nLevel = nLevel;
}
//获取性别
uint8_t OfflineCharacterData::GetSex()
{
	return m_bySex;
}
//设置性别
void OfflineCharacterData::SetSex(uint8_t bySex)
{
	m_bySex = bySex;
}
//获取职业
uint8_t OfflineCharacterData::GetProf()
{
	return m_byProf;
}
//设置职业
void OfflineCharacterData::SetProf(uint8_t byProf)
{
	m_byProf = byProf;
}
//获取种族
int32_t OfflineCharacterData::GetRace()
{
	return m_nRace;
}
//种族
void OfflineCharacterData::SetRace(int32_t nRace)
{
	m_nRace = nRace;
}
//获取战力
int32_t OfflineCharacterData::GetFight()
{
	return m_nFight;
}
//设置战力
void OfflineCharacterData::SetFight(int32_t nFight)
{
	m_nFight = nFight;
}
//获取阵营ID
int8_t OfflineCharacterData::GetCampID()
{
	return m_byCampID;
}
//设置阵营ID
void OfflineCharacterData::SetCampID(int8_t byCampID)
{
	m_byCampID = byCampID;
}
//获取官职
uint32_t OfflineCharacterData::GetOfficial()
{
	return m_byOfficial;
}
//设置官职
void OfflineCharacterData::SetOfficial(uint32_t byOfficial)
{
	m_byOfficial = byOfficial;
}
//获取爵位
uint32_t OfflineCharacterData::GetKnight()
{
	return m_byKnight;
}
//设置爵位
void OfflineCharacterData::SetKnight(uint32_t byKnight)
{
	m_byKnight = byKnight;
}

//获取声望
uint32_t OfflineCharacterData::GetPrestige()
{
	return m_nPrestige;
}
//设置声望
void OfflineCharacterData::SetPrestige(uint32_t byPrestige)
{
	m_nPrestige = byPrestige;
}

//获取历史声望
uint32_t OfflineCharacterData::GetHisPrestige()
{
	return m_nHisPrestige;
}
//设置历史声望
void OfflineCharacterData::SetHisPrestige(uint32_t byPrestige)
{
	m_nHisPrestige = byPrestige;
}

//获取军功
uint32_t OfflineCharacterData::GetContribute()
{
	return m_byContribute;
}
//设置军功
void OfflineCharacterData::SetContribute(uint32_t byContribute)
{
	m_byContribute = byContribute;
}

//获取军功币
uint32_t OfflineCharacterData::GetContriCoin()
{
	return m_byContriCoin;
}
//设置军功币
void OfflineCharacterData::SetContriCoin(uint32_t byContriCoin)
{
	m_byContriCoin = byContriCoin;
}

//获取击杀数
uint32_t OfflineCharacterData::GetKillCount()
{
	return m_nKillCount;
}
//设置击杀数
void OfflineCharacterData::SetKillCount(uint32_t nKillCount)
{
	m_nKillCount = nKillCount;
}

//获取工会可用贡献
uint32_t OfflineCharacterData::GetUnionUseContri()
{
	return m_useUnionContri;
}
//设置工会可用贡献
void OfflineCharacterData::SetUnionUseContri(uint32_t useContri)
{
	m_useUnionContri = useContri;
}

//获取历史贡献
uint32_t OfflineCharacterData::GetHistoryContri()
{
	return m_historyContri;
}
//设置历史贡献
void OfflineCharacterData::SetHistoryContri(uint32_t historyContri)
{
	m_historyContri = historyContri;
}

//获得遗失之城累计积分
uint32_t OfflineCharacterData::GetLostCityVal()
{
	return m_lostCityVal;
}
//设置遗失之城累计积分
void OfflineCharacterData::SetLostCityVal(uint32_t nVal)
{
	m_lostCityVal = nVal;
}

//清空阵营数据
void OfflineCharacterData::ClearCamp()
{
	m_byCampID = 0;
	m_byKnight = 0;
	m_byOfficial = 0;
	m_byContribute = 0;
	m_byContriCoin = 0;
	m_nKillCount = 0;
}

//这里只是对少数一些属性进行记录。
void OfflineCharacterData::AttrUpdate(const ::google::protobuf::RepeatedPtrField< ::ProtoBuf::CharSyncAttr >& syncAttr)
{
	for (int32_t i = 0; i < syncAttr.size(); i++)
	{
		if (syncAttr.Get(i).attrid() == C_LEVEL)
		{
			int16_t value = int16_t(syncAttr.Get(i).attrval());
			SetLevel(value);
		}
		else if (syncAttr.Get(i).attrid() == C_GOLD)
		{
			m_intGold = syncAttr.Get(i).attrval();
		}
		else if (syncAttr.Get(i).attrid() == C_DIAMOND_BIND)
		{
			m_intDiamond = syncAttr.Get(i).attrval();
		}
		else if (syncAttr.Get(i).attrid() == C_FIGHT_POWER)
		{
			m_nFight = syncAttr.Get(i).attrval();
		}
		else if (syncAttr.Get(i).attrid() == C_EXP)
		{
			m_exp = syncAttr.Get(i).attrval();
		}
		else if (syncAttr.Get(i).attrid() == C_HP)
		{
			m_hp = syncAttr.Get(i).attrval();
		}
		else if (syncAttr.Get(i).attrid() == C_MAX_HP)
		{
			m_maxHp = syncAttr.Get(i).attrval();
		}
	}
}

//获取外观
const CharFacadeProto & OfflineCharacterData::GetFacade()
{
	return m_facade;
}
//设置外观
void OfflineCharacterData::SetFacade(const CharFacadeProto &facade)
{
	m_facade = facade;
}

//获取最近下线时间
uint64_t OfflineCharacterData::GetLastLogout()
{
	return m_lastLogout;
}
//设置最近下线时间
void OfflineCharacterData::SetLastLogout(uint64_t lastLogout)
{
	m_lastLogout = lastLogout;
}

//获取金币
uint32_t OfflineCharacterData::GetGold()
{
	return m_intGold;
}
//获取钻石
uint32_t OfflineCharacterData::GetDiamond()
{
	return m_intDiamond;
}
//经验
uint32_t OfflineCharacterData::GetExp()
{
	return m_exp;
}
//血量
uint32_t OfflineCharacterData::GetHp()
{
	return m_hp;
}
//最大血量
uint32_t OfflineCharacterData::GetMaxHp()
{
	return m_maxHp;
}
//get 魅力值
uint32_t OfflineCharacterData::GetCharm()
{
	return m_charm;
}
//set 魅力值
void OfflineCharacterData::SetCharm(uint32_t value)
{
	m_charm = value;
}

void OfflineCharacterData::SetChannelId(uint32_t chanelId)
{
	m_channelId = chanelId;
}

uint16_t OfflineCharacterData::GetChannelId()
{
	return m_channelId;
}

//设置成就积分
void OfflineCharacterData::SetAchievementPoint(AchievementType type, uint32_t value)
{
	if (type>AchievementType::ACHIEVEMENT_TYPE_ADVENTURE || type<ACHIEVEMENT_TYPE_PERSION)
	{
		LogErrFmtPrint("OfflineCharacterData::SetAchievementPoint type=%d error", type);
		return;
	}
	m_arrAchievementPoint[type - 1] = value;
}
//获取成就积分
uint32_t OfflineCharacterData::GetAchievementPoint(AchievementType type)
{
	if (type>AchievementType::ACHIEVEMENT_TYPE_ADVENTURE || type < ACHIEVEMENT_TYPE_PERSION)
	{
		LogErrFmtPrint("OfflineCharacterData::GetAchievementPoint type=%d error", type);
		return 0;
	}
	return m_arrAchievementPoint[type - 1];
}